package com.yao.system.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yao.system.entity.JobCategory;
import com.yao.system.entity.PageResult;
import com.yao.system.entity.Result;
import com.yao.system.entity.User;
import com.yao.system.mapper.JobCategoryMapper;
import com.yao.system.service.IJobCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 霖
 * @since 2024-04-22
 */
@Service
public class JobCategoryServiceImpl extends ServiceImpl<JobCategoryMapper, JobCategory> implements IJobCategoryService {

    /**
     * 查询岗位分类列表
     *
     * @return
     */
    @Override
    public Result getList() {
        List<JobCategory> categoryList = list();
        return Result.ok(categoryList);
    }

    @Override
    public Result queryjobCategoryList(Integer page, Integer size) {
        Page<JobCategory> categoryPage = lambdaQuery()
                .page(Page.of(page, size));
        List<JobCategory> categoryList = categoryPage.getRecords();
        int total = (int) categoryPage.getTotal();
        int pages = (int) categoryPage.getPages();
        if (CollectionUtil.isEmpty(categoryList)) {
            Result.ok(PageResult.of(total, pages, null));
        }
        return Result.ok(PageResult.of(total, pages, categoryList));
    }

    @Override
    public Result updatejobCategoryAdmin(JobCategory category) {
        updateById(category);
        return Result.ok("修改成功");
    }
}
